#!/bin/sh
# This regression test is a part of SIPp.
# A message trace over the file size limit (SIGXFSZ) stops the traces:
# SIPp says so in <scenario>_<pid>_traces_oversized.log and closes the
# trace, and the calls go on.
. "`dirname "$0"`/../functions"; init

test -d /proc/self/fd || skip "no /proc"

sipp="`get_sipp`"
dir=`mktemp -d`
trap 'rm -rf "$dir"' EXIT
cd "$dir"

sippbg -sn uas -i 127.0.0.1 -p 26180 -m 3 -timeout 15
# Three calls of 4 s, whose messages go over 4 KB (8 blocks) at once.
(ulimit -f 8 && exec "$sipp" -nostdin -sn uac -i 127.0.0.1 -p 26181 \
    -m 3 -l 3 -r 10 -d 4000 127.0.0.1:26180 -trace_msg -timeout 15 \
    -timeout_error >/dev/null 2>&1) &
uac=$!
sleep 2
open=`ls -l /proc/$uac/fd 2>/dev/null | grep -c '_messages\.log'`
wait $uac
status=$?

if test $status -ne 0; then
    fail "exited with $status"
elif ! grep -q '^Max file size reached - no more logs$' uac_*_traces_oversized.log 2>/dev/null; then
    fail "no oversized traces log"
elif test "$open" -ne 0; then
    fail "the messages log is still open"
else
    ok
fi
